<?php
namespace Admin\Controller;
use Think\Controller;


class ArtController extends Controller {

    public function artadd(){
        if (!checkCookie()) {
            $this->redirect('Admin/Index/login');
        }
        if (!IS_POST) {
            $catModel = D('cat');
            $cid      =  I('cid');
            $cats     =  $catModel->select();
            $this->assign('cats',$cats);
            $this->assign('cid',$cid);
            $this->display();
        }else{
            $artModel=D('article');
            $_POST['is_del']=0;
            $_POST['ctime']=time();
            $_POST['utime']=time();
            if ($artModel->add($_POST)) {
                $this->success("添加成功",(U('Admin/art/artlist',['cid'=>$_POST['cid']])));
            }else{
                $this->error("添加失败");
            }
        }
    }
    public function artlist(){
        if (!checkCookie()) {
            $this->redirect('Admin/Index/login');
        }
        $where['cid'] = I('cid');
        $where['is_del'] = 0;
        $artModel = D('article');
        $count = $artModel->where($where)->count();
        $Page  = new \Think\Page($count,10);
        $arts = $artModel->where($where)->order('ctime desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $show = $Page->show();
        $this->assign('page',$show);
        $this->assign('cid',$where['cid']);
        $this->assign('arts',$arts);
        $this->display();
    }

    public function artedit(){
        if (!checkCookie()) {
            $this->redirect('Admin/Index/login');
        }
        $artModel = D('article');
    	if (!IS_POST) {
            $catModel = D('cat');
            $cats     =  $catModel->select();
            $art_id = I('aid');
            $art  = $artModel->find($art_id); 
            $this->assign('cats',$cats);
            $this->assign('art',$art); 
            $this->display();
    	}else{
            $artModel->cid=$_POST['cid']; 
            $artModel->title=$_POST['title']; 
            $artModel->pic1=$_POST['pic1'];
            $artModel->discrip1=$_POST['discrip1'];
            $artModel->content1=$_POST['content1'];
            $artModel->content=$_POST['content'];
            $artModel->pic2=$_POST['pic2'];
            $artModel->video_link=$_POST['video_link'];
            $artModel->discrip2=$_POST['discrip2'];
            $artModel->content2=$_POST['content2'];
            $artModel->pic3=$_POST['pic3'];
            $artModel->discrip3=$_POST['discrip3'];
            $artModel->content3=$_POST['content3'];
            $artModel->pic4=$_POST['pic4'];
            $artModel->discrip4=$_POST['discrip4'];
            $artModel->content4=$_POST['content4'];
            $artModel->pic5=$_POST['pic5'];
            $artModel->discrip5=$_POST['discrip5'];
            $artModel->content5=$_POST['content5'];
            $artModel->pic6=$_POST['pic6'];
            $artModel->discrip6=$_POST['discrip6'];
            $artModel->content6=$_POST['content6'];
            $artModel->ymd=$_POST['ymd'];
            $artModel->utime=time();
            if ($artModel->where('aid='.$_POST['aid'])->save()) {
                $this->success("修改成功",(U('Admin/art/artlist',['cid'=>$_POST['cid']])));
            }else{
                $this->error("修改失败");
            }
        }
    }
    public function del(){
        if (!checkCookie()) {       
            $this->redirect('Admin/Index/login');
        }
        $aid = I('get.id');
        $res = M('article')->delete($aid);
        if ($res) {
            $this->success('删除成功',(U('Admin/art/artlist')));
        }else{
            $this->error('删除失败');
        }
    }
    public function ueditor(){
        $data = new \Org\Util\Ueditor();
        echo $data->output();
    }
    public function foud(){
        $foudModel = D('foud');
        if(!empty($_POST)){
             $data = $foudModel->create();
            if($foudModel->where('fid='.$_POST['fid'])->save()){
                 $this->success("修改成功",redirect(U('Admin/art/foud')));
            }else{
                $this->error('修改失败'); 
            }
        }
        $foud = $foudModel->find('1');
        $this->assign('foud',$foud);
        $this->display();
    }
    public function videoadd(){
        if (!checkCookie()) {
            $this->redirect('Admin/Index/login');
        }
        if (!IS_POST) {
            $catModel = D('cat');
            $cid      =  I('cid');
            $cats     =  $catModel->select();
            $this->assign('cats',$cats);
            $this->assign('cid',$cid);
            $this->display();
        }else{
            $artModel=D('article');
            $_POST['is_del']=0;
            $_POST['ctime']=time();
            $_POST['utime']=time();
            if ($artModel->add($_POST)) {
                $this->success("添加成功",(U('Admin/art/artlist',['cid'=>$_POST['cid']])));
            }else{
                $this->error("添加失败");
            }
        }
    }
}